home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / ANSI Headers / fstream < prev    next >
Encoding:
Text File  |  1994-10-20  |  3.5 KB  |  149 lines  |  [TEXT/MMCC]

  1. // fstream standard header
  2. #ifndef _FSTREAM_
  3. #define _FSTREAM_
  4. #include <istream>
  5. #include <ostream>
  6.  
  7. #if __MWERKS__
  8. #pragma options align=mac68k
  9. #endif
  10.  
  11.   // class filebuf
  12. struct _Filet;
  13. class filebuf : public streambuf {
  14. public:
  15.  filebuf(_Filet *_F = 0)
  16.   {_Init(_F); }
  17.  filebuf(ios::_Uninitialized)
  18.   : streambuf(ios::_Noinit) {}
  19.  virtual ~filebuf();
  20.  _Bool is_open() const
  21.   {return ((_File != 0)); }
  22.  filebuf *open(const char *, ios::openmode);
  23.  filebuf *open(const char *_N, ios::open_mode _M)
  24.   {return (open(_N, (ios::openmode)_M)); }
  25.  filebuf *close();
  26. protected:
  27.  virtual int overflow(int = EOF);
  28.  virtual int pbackfail(int = EOF);
  29.  virtual int underflow();
  30.  virtual int uflow();
  31.  virtual int xsgetn(char *, int);
  32.  virtual int xsputn(const char *, int);
  33.  virtual streampos seekoff(streamoff, ios::seekdir,
  34.   ios::openmode = (ios::openmode)(ios::in | ios::out));
  35.  virtual streampos seekpos(streampos,
  36.   ios::openmode = (ios::openmode)(ios::in | ios::out));
  37.  virtual streambuf *setbuf(char *, int);
  38.  virtual int sync();
  39.  _Filet *_Init(_Filet * = 0, _Bool = 0);
  40. private:
  41.  _Bool _Closef;
  42.  _Filet *_File;
  43.  };
  44.   // class ifstream
  45. class ifstream : public istream {
  46. public:
  47.  ifstream()
  48.   : ios(&_Fb), istream(&_Fb) {}
  49.  ifstream(const char *_S, openmode _M = in)
  50.   : ios(&_Fb), istream(&_Fb) {_Fb.open(_S, _M); }
  51.  virtual ~ifstream();
  52.  filebuf *rdbuf() const
  53.   {return ((filebuf *)&_Fb); }
  54.  _Bool is_open() const
  55.   {return (_Fb.is_open()); }
  56.  void open(const char *_S, openmode _M = in)
  57.   {if (_Fb.open(_S, _M) == 0)
  58.     setstate(failbit); }
  59.  void open(const char *_S, open_mode _M)
  60.   {open(_S, (openmode)_M); }
  61.  void close()
  62.   {if (_Fb.close() == 0)
  63.     setstate(failbit); }
  64. private:
  65.  filebuf _Fb;
  66.  };
  67.   // class ofstream
  68. class ofstream : public ostream {
  69. public:
  70.  ofstream()
  71.   : ios(&_Fb), ostream(&_Fb) {}
  72.  ofstream(const char *_S, openmode _M = out | trunc)
  73.   : ios(&_Fb), ostream(&_Fb) {_Fb.open(_S, _M); }
  74.  virtual ~ofstream();
  75.  filebuf *rdbuf() const
  76.   {return ((filebuf *)&_Fb); }
  77.  _Bool is_open() const
  78.   {return (_Fb.is_open()); }
  79.  void open(const char *_S, openmode _M = out | trunc)
  80.   {if (_Fb.open(_S, _M) == 0)
  81.     setstate(failbit); }
  82.  void open(const char *_S, open_mode _M)
  83.   {open(_S, (openmode)_M); }
  84.  void close()
  85.   {if (_Fb.close() == 0)
  86.     setstate(failbit); }
  87. private:
  88.  filebuf _Fb;
  89.  };
  90.   // class stdiobuf
  91. class stdiobuf : public filebuf {
  92. public:
  93.  stdiobuf(_Filet *_F)
  94.   : filebuf(_F), _Is_buffered(0) {}
  95.  virtual ~stdiobuf();
  96.  _Bool buffered() const
  97.   {return (_Is_buffered); }
  98.  void buffered(_Bool _F)
  99.   {_Is_buffered = _F; }
  100. private:
  101.  _Bool _Is_buffered;
  102.  };
  103.   // class istdiostream
  104. class istdiostream : public istream {
  105. public:
  106.  istdiostream(_Filet *_F)
  107.   : ios(&_Fb), istream(&_Fb), _Fb(_F) {}
  108.  virtual ~istdiostream();
  109.  stdiobuf *rdbuf() const
  110.   {return ((stdiobuf *)&_Fb); }
  111.  _Bool buffered() const
  112.   {return (_Fb.buffered()); }
  113.  void buffered(_Bool _F)
  114.   {_Fb.buffered(_F); }
  115. private:
  116.  stdiobuf _Fb;
  117.  };
  118.   // class ostdiostream
  119. class ostdiostream : public ostream {
  120. public:
  121.  ostdiostream(_Filet *_F)
  122.   : ios(&_Fb), ostream(&_Fb), _Fb(_F) {}
  123.  virtual ~ostdiostream();
  124.  stdiobuf *rdbuf() const
  125.   {return ((stdiobuf *)&_Fb); }
  126.  _Bool buffered() const
  127.   {return (_Fb.buffered()); }
  128.  void buffered(_Bool _F)
  129.   {_Fb.buffered(_F); }
  130. private:
  131.  stdiobuf _Fb;
  132.  };
  133.  
  134. #if __MWERKS__
  135. #pragma options align=reset
  136. #endif
  137.  
  138. #endif
  139.  
  140. /*
  141.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  142.  * Consult your license regarding permissions and restrictions.
  143.  */
  144.  
  145. /* Change log:
  146.  *94Oct03 Version received from PlumHall
  147.  *94Oct07 Inserted MW changes.
  148.  */
  149.